////////////////////////////////////////////////////////////////////////////////
//Copyright 2009 Christopher Betancourt
//
//This file is part of PEAQ
//
//PEAQ is free software: you can redistribute it and/or modify it under the 
//terms of the GNU Lesser General Public License as published by the Free 
//Software Foundation, either version 3 of the License, or (at your option) any
//later version.
//
//PEAQ is distributed in the hope that it will be useful, but WITHOUT ANY 
//WARRANTY; without even the implied warranty of MERCHANTABLILTY or FITTNESS FOR
//A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
//details.
//
//You should have received a copy of the GNU Lesser Public License with PEAQ.  
//If not, see <http://www.gnu.org/licenses/>.
///////////////////////////////////////////////////////////////////////////////
package gui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.table.TableCellRenderer;

public class ColorRenderer implements TableCellRenderer {
	private Border sBorder;
	private Border uBorder;
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		JLabel retVal=new JLabel();
		
		retVal.setBorder(new LineBorder((Color)value));
		retVal.setOpaque(true);
		retVal.setBackground((Color)value);
		
		if(isSelected)
		{
			if(sBorder==null)
				sBorder=BorderFactory.createMatteBorder(2, 5, 2, 5, table.getSelectionBackground());
			retVal.setBorder(sBorder);
		}
		else
		{
			if(uBorder==null)
				uBorder=BorderFactory.createMatteBorder(2, 5, 2, 5, table.getBackground());
			retVal.setBorder(uBorder);
		}
		
		return retVal;
	}

}
